﻿
ierd_tgp.tpf_ui.Require("auto_update_guide\\view.lua")
ierd_tgp.tpf_ui.Require("auto_update_guide\\control.lua");
ierd_tgp.tpf_ui.Require("auto_update_guide\\item.lua");

Item = {
    selected_ = false;
    in_hover_ = false;
};

UpdateListItemUIEventListener = {
};

function Item:new(game_id, wrapper_id)
    base_utility.log(string.format("Item:new %d %d", game_id, wrapper_id));
    local o = { game_id_ = game_id, wrapper_id_ = wrapper_id }
    setmetatable(o, self)
    self.__index = self
    return o
end

function Item:log(msg, core_msg)
    base_utility.log(string.format("[Item][%d] %s", self.game_id_, msg), core_msg);
end

function Item:show_hover_mask(show)

    local behavior_enter = ui_utility.get_ctrl_ptr_by_path(
        self.wrapper_id_, "CntHighlight\\BehaviorEnter");
    local behavior_leave = ui_utility.get_ctrl_ptr_by_path(
        self.wrapper_id_, "CntHighlight\\BehaviorLeave");
    local mask = ui_utility.get_ctrl_ptr_by_path(
        self.wrapper_id_, "CntHighlight");

    if nil == behavior_enter or nil == behavior_leave then
        self:log(string.format(
        "[show_hover_mask], behavior_enter or behavior_leave is nil"));
        return;
    end

    if show then
        self:log(string.format("[show_hover_mask]play enter animation for hove mask"));
        behavior_leave:Stop();
        behavior_enter:Start();
    else
        self:log(string.format("[show_hover_mask]play leave animation for hove mask"));
        behavior_enter:Stop();
        behavior_leave:Start();
    end
end

function Item:on_hover(show)
    self:log(string.format("[on_hover]on_hover:%s ",
        tostring(show)));

    self.in_hover_ = show;

    if not self.selected_ then
        self:show_hover_mask(show);
    else
        self:log(string.format("[on_hover]do not play hover animation for selected game"));
    end
end

-----------------------------UpdateListItemUIEventListener----------------------------------

function UpdateListItemUIEventListener.on_item_mouse_hover(uilib, control_id, x, y, id_message_from)
    base_utility.log(string.format(
        "[UpdateListItemUIEventListener]on_item_mouse_hover ctrl_id:%d",
        control_id));
    local item_id = ui_utility.get_ctrl_parent_id(control_id);
    local item = update_guide_tips_control.ctrl2item[item_id];
    if nil == item then
        base_utility.log(string.format(
            "[UpdateListItemUIEventListener][on_item_mouse_hover]item is NIL," ..
            " ctrl_id:%d", control_id), true);
        return;
    end

    -- 去除hover状态逻辑
    -- item:on_hover(true);
end

function UpdateListItemUIEventListener.on_item_mouse_leave(uilib, control_id, x, y, id_message_from)
    base_utility.log(string.format(
        "[UpdateListItemUIEventListener]on_item_mouse_leave ctrl_id:%d",
        control_id));
    local item_id = ui_utility.get_ctrl_parent_id(control_id);
    local item = update_guide_tips_control.ctrl2item[item_id];
    if nil == item then
        base_utility.log(string.format(
        "[UpdateListItemUIEventListener][on_item_mouse_leave]item is NIL," ..
        " ctrl_id:%d", control_id), true);
        return;
    end
    -- 去除hover状态逻辑
    -- item:on_hover(false);
end

